package com.suny;

public class Thread1 {
    public static void main(String[] args) throws InterruptedException {
        Thread1 thread1 = new Thread1();
        thread1.testWait();
//        testWaitNoLock();
    }

    public static void testWaitNoLock() throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("ready wait----------");
            }
        });
        thread.start();
        long start = System.currentTimeMillis();
        thread.wait(3000);
        long end = System.currentTimeMillis();
        System.out.println(end - start + ": wait finish----------");
    }

    public void testWait() throws InterruptedException {
        Object obj = new Object();
        synchronized (this) {
            System.out.println("ready wait----------");
            long start = System.currentTimeMillis();
            obj.wait(3000);
            long end = System.currentTimeMillis();
            System.out.println(end - start + ": wait finish----------");
        }
    }
}
